package com.smh.a01immutableDemo1;

import java.util.Iterator;
import java.util.List;

public class ImmutableDemo1 {
    public static void main(String[] args) {

        //创建不可变list集合


        List<String> list = List.of("asd","qwe","zxc");

        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("-------------");
        list.forEach(s->{
            System.out.println(s);
        });
        System.out.println("-------------");
        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println("-------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("-------------");
        //不让改
        list.set(1,"asd");
        list.add("zxcc");
        list.remove("asd");

    }
}
